from django.db import models

class Cloud(models.Model):
    '''
    定义云厂商
    '''
    name = models.CharField("云厂商名称",max_length=48,help_text="云厂商名称")
    code = models.CharField("云厂商简称",max_length=48,help_text="云厂商简称")

    def __str__(self):
        return self.code

class Server(models.Model):
    '''
    定义云服务器
    '''
    cloud = models.ForeignKey(Cloud)
    instanceId = models.CharField("实例ID",max_length=128,db_index=True,help_text="实例ID")
    instanceType = models.CharField("实例类型",max_length=128,help_text="实例类型")
    cpu = models.CharField("cpu",max_length=24,help_text="cpu")
    memory = models.CharField("memory",max_length=24,help_text="memory")
    instanceName = models.CharField("实例名称",max_length=128,db_index=True,help_text="实例名称")
    createTime = models.DateTimeField("创建时间",db_index=True)
    expiredTime = models.DateTimeField("到期时间",db_index=True)
    osname = models.CharField("操作系统版本",max_length=100,help_text="操作系统版本")

class Ip(models.Model):
    '''
    定义IP
    '''
    ip = models.GenericIPAddressField(db_index=True)
    inner = models.ForeignKey(Server,related_name="innerIpAddress",null=True)
    public = models.ForeignKey(Server,related_name="publicIpAddress",null=True)